package com.hpf.lease.web.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hpf.lease.common.result.Result;
import com.hpf.lease.model.bean.SystemPost;
import com.hpf.lease.web.admin.service.SystemPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/post")
@Tag(name = "用户岗位管理模块")
public class SystemPostController {
    @Resource
    SystemPostService service;
    @PostMapping("/updateStatusByPostId")
    @Operation(summary = "根据岗位id修改状态")
    public Result<Object> updateStatusByPostId(@RequestParam long id ,
                                               @RequestParam Integer status){
        return Result.build(service.update(Wrappers.lambdaUpdate(SystemPost.class)
                .eq(SystemPost::getId , id)
                .set(SystemPost::getStatus , status)));
    }
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或更新岗位信息")
    public Result<Object> saveOrUpdate(@RequestBody SystemPost systemPost){
        return Result.build(service.saveOrUpdateInfo(systemPost));
    }
    @GetMapping("/page")
    @Operation(summary = "分页获取岗位信息")
    public Result<Page<SystemPost>> getPageItem(@RequestParam Integer current , @RequestParam Integer size){
        return Result.ok(service.getPageItem(current,size));
    }
    @GetMapping("/list")
    @Operation(summary = "获取全部岗位列表")
    public Result<List<SystemPost>> listAll(){
        return Result.ok(service.list());
    }
    @GetMapping("/getById")
    @Operation(summary = "根据id获取岗位信息")
    public Result<SystemPost> getById(@RequestParam long id){
        return Result.ok(service.getById(id));
    }
    @DeleteMapping("/deleteById")
    @Operation(summary = "根据id删除岗位")
    public Result<Object> deleteById(@RequestParam long id){
        return Result.build(service.removeById(id));
    }
}
